package com.santiao.fuel.ui.widget

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager

class PersonalViewpager: ViewPager {
    private var canScroll:Boolean=true
    constructor(context: Context) : super(context)
    constructor(context: Context,attrs:AttributeSet):super(context, attrs)

    @OptIn(ExperimentalStdlibApi::class)
    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        var height = 0
        for (i in 0..<childCount) {
            val child = getChildAt(i);
            child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            val h = child.measuredHeight
            if (h > height)
                height = h
        }
        super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY))
    }

    fun setCanScroll(canScroll : Boolean){
        this.canScroll=canScroll
    }

    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        return canScroll
    }
}